<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	
</body>
</html>
<script>
var FocusScorll = (function(){
	var FocusScorll = function(id){
    this._id = id;
    this.pullDownFlag = 0;
    this.pullUpFlag = 0;
    this.pullDown = document.getElementById("pullDown");
    this.pullUp = document.getElementById("pullUp");
    this.spinner = document.getElementById("spinner");
    this.myScroll = null;
    this.init();
FocusScorll.prototype.init= function(){
    console.log("id:" + this._id);
    this.myScroll = new IScroll("#"+this._id,{
        probeType: 3,
        mouseWheel: true,//鼠标滑轮开启
        scrollbars: true,//滚动条可见
        fadeScrollbars: true,//滚动条渐隐
        interactiveScrollbars: true,//滚动条可拖动
        shrinkScrollbars: 'scale', // 当滚动边界之外的滚动条是由少量的收缩
        useTransform: true,//CSS转化
        useTransition: true,//CSS过渡
        bounce: true,//反弹
        freeScroll: false,//只能在一个方向上滑动
        startX: 0,
        startY: 0,
    });
    
    this.myScroll.on('scroll',_this.positionJudge);
    this.myScroll.on("scrollEnd",_this.action);
};
FocusScorll.prototype.positionJudge= function(){
    if(this.y>40){    //判断下拉
        _this.pullDown.style.display="block";
        _this.pullDown.innerHTML = "松开刷新页面";
        _this.pullDownFlag = 1;
    }else if(this.y<(this.maxScrollY-40)){   //判断上拉
        _this.pullUp.style.display="block";
        _this.pullUp.innerHTML = "松开刷新页面";
        _this.pullUpFlag = 1;
    }
};
FocusScorll.prototype.action = function(){
     if(_this.pullDownFlag==1){
        _this.pullDownAction();
        _this.pullDown.innerHTML = "正在加载…";
        _this.pullDownFlag = 0;
    }else if(_this.pullUpFlag==1){
        _this.pullUpAction();
        _this.pullUp.innerHTML = "正在加载…";
        _this.pullUpFlag = 0;
    }
};
FocusScorll.prototype.pullDownAction= function(){
    News.listInitFocus();
    setTimeout(function(){
             $(".scrollcontent").height($(document).height()-90);
             _this.myScroll.refresh();
         _this.pullDown.style.display="none";
    },500);
};
FocusScorll.prototype.pullUpAction= function(){
     _this.getData();
    setTimeout(function(){
        _this.myScroll.refresh();
        _this.pullUp.style.display="none";
    },200);
};
FocusScorll.prototype.updatePosition= function(){
     _this.pullDown.innerHTML = this.y>>0;
};
FocusScorll.prototype.getData= function(){
     console.log("_id:" + _this._id);
        var id = $(".selected").text();
        var num =  parseInt($("#"+id+"num").val())+1;
        $("#"+id+"num").val(num);
        alert("num:" + num + ",id:" + id);
       $ajax({
            url:"/news/fenye", 
            data:{
                num:num
            }, 
            success:function(res){
             var item=res.result;
              var html = "";
              if(item.length<=0){
                  //
                  alert("已经是最后一页了！");
              }else{
                  $.each(item,function(j,news){
                    html+=News.getNewsHtml(news);
                    });
                }
                $("#" + id + "1").append(html);
                _this.myScroll.refresh();
                //_this.myScroll.scrollTo(0,0,100);
            },
            error:function(){
                alert("1");
            }
        });
};
return function(id){
    return new FocusScorll(id);
}
}
})();
var c1 = new FocusScroll("c1");
var c2 = new FocusScroll("c2");
var c3 = new FocusScroll("c3");
</script>